﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShipsLog.Model
{
    public static class LeadingEdgeEmumerable
    {
        public static IEnumerable<T> OnlyDiffernt<T>(this IEnumerable<T> data, Func<T, T, bool> comparer)
        {
            T previous = default(T);
            bool first = true;
            foreach (T value in data)
            {
                if (first)
                {
                    previous = value;
                    first = false;
                    yield return value;
                }
                else
                {
                    if (comparer(previous, value)) 
                    {
                        yield return value;
                    }
                }
                
            }
        }
    }
}
